package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo10 {
    public static void main(String[] args) {
        try(Connection connection=DBUtil.getConnection();) {
            connection.setAutoCommit(false);
            String sql="delete from user where id=? ";
            PreparedStatement ps=connection.prepareStatement(sql);
            ps.setInt(1,3);
            int num=ps.executeUpdate();
            System.out.println(num>0?"删除成功":"删除失败");
            //connection.rollback();//假删除
            connection.commit();//真删除，不可逆
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
